package com.wtwd.campus.controller;

import com.alibaba.fastjson.JSON;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.common.RespCode;
import com.wtwd.campus.common.RespCodeEntity;
import com.wtwd.campus.config.ProducerConfig;
import com.wtwd.campus.entity.*;
import com.wtwd.campus.utils.ByteObjectUtils;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/up")
public class ReceiveUpController {
    private static final Logger logger = LoggerFactory.getLogger(ReceiveUpController.class);
    @Autowired
    private DefaultMQProducer producer;
    @Autowired
    private ProducerConfig producerConfig;

    /**
     * 主动查询定位的回复
     *
     * @param mqDeviceUpLocation
     * @return
     */
    @PostMapping("/queryLocationResponse")
    RespCodeEntity queryLocationResponse(@RequestBody MqDeviceUpLocation mqDeviceUpLocation) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.ACTIVE_DEVICE_LOCATION, mqDeviceUpLocation);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 查询设备参数的回复
     *
     * @param mqDeviceParam
     * @return
     */
    @PostMapping("/queryParamResponse")
    RespCodeEntity queryParamResponse(@RequestBody MqDeviceParam mqDeviceParam) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.DEVICE_PARAMETERS, mqDeviceParam);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 查询Iccid和Sim卡的回复
     *
     * @param mqIccidAndSimCard
     * @return
     */
    @PostMapping("/querySimCardAndIccidResponse")
    RespCodeEntity querySimCardAndIccidResponse(@RequestBody MqIccidAndSimCard mqIccidAndSimCard) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.ICCID_AND_SIM, mqIccidAndSimCard);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 查询设备imeid
     *
     * @param mqDeviceImeid
     * @return
     */
    @PostMapping("/queryImeidResponse")
    RespCodeEntity queryImeidResponse(@RequestBody MqDeviceImeid mqDeviceImeid) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.DEVICE_IMEID, mqDeviceImeid);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置临时监控中心回复
     *
     * @param mqIpAndPortResult
     * @return
     */
    @PostMapping("/tempControlCenterResponse")
    RespCodeEntity tempControlCenterResponse(@RequestBody MqIpAndPortResult mqIpAndPortResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_TEMPORARY_CONTROL_CENTER, mqIpAndPortResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }


    /**
     * 设置默认监控中心回复
     *
     * @param mqIpAndPortResult
     * @return
     */
    @PostMapping("/defaultControlCenterResponse")
    RespCodeEntity defaultControlCenterResponse(@RequestBody MqIpAndPortResult mqIpAndPortResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_DEFAULT_CONTROL_CENTER, mqIpAndPortResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置工作模式的回复
     *
     * @param mqModeResult
     * @return
     */
    @PostMapping("/modeResponse")
    RespCodeEntity modeResponse(@RequestBody MqModeResult mqModeResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_WORK_MODE, mqModeResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置上报间隔的回复
     *
     * @param mqUploadResult
     * @return
     */
    @PostMapping("/uploadResponse")
    RespCodeEntity uploadResponse(@RequestBody MqUploadResult mqUploadResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_UPLOAD_TIME, mqUploadResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置闲时自动切换的回复
     *
     * @param mqAutoChangeModeResult
     * @return
     */
    @PostMapping("/sleepAutoChangeModeResponse")
    RespCodeEntity sleepAutoChangeModeResponse(@RequestBody MqAutoChangeModeResult mqAutoChangeModeResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.AUTO_CHANGE_WORK_MODE, mqAutoChangeModeResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 监听号码设置的结果
     *
     * @param mqMonitorResult
     * @return
     */
    @PostMapping("/monitorResponse")
    RespCodeEntity monitorResponse(@RequestBody MqMonitorResult mqMonitorResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_MONITOR_NUMBER, mqMonitorResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置课堂模式的回复
     *
     * @param mqClassModeResult
     * @return
     */
    @PostMapping("/classModeResponse")
    RespCodeEntity classModeResponse(@RequestBody MqClassModeResult mqClassModeResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_NO_DISTURB_TIME, mqClassModeResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置课堂模式开关的回复
     *
     * @param mqGeneralSwitchResult
     * @return
     */
    @PostMapping("/classModeSwitchResponse")
    RespCodeEntity classModeSwitchResponse(@RequestBody MqGeneralSwitchResult mqGeneralSwitchResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_NO_DISTURB_SWITCH, mqGeneralSwitchResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置课表考勤开关
     *
     * @param mqGeneralSwitchResult
     * @return
     */
    @PostMapping("/callFunResponse")
    RespCodeEntity callFunResponse(@RequestBody MqGeneralSwitchResult mqGeneralSwitchResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_NO_DISTURB_CONTROLLER, mqGeneralSwitchResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置PDOP门限回复
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/setPDOPResponse")
    RespCodeEntity setPDOPResponse(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_PDOP_THRESHOLD_VALUE, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置SOS开关回复
     *
     * @param mqGeneralSwitchResult
     * @return
     */
    @PostMapping("/sosSwitchResponse")
    RespCodeEntity sosSwitchResponse(@RequestBody MqGeneralSwitchResult mqGeneralSwitchResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SET_SOS_DIAL_SWITCH, mqGeneralSwitchResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 恢复出厂设置的回复
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/reSetDeviceResponse")
    RespCodeEntity reSetDeviceResponse(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.FACTORY_RESET, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 重启回复
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/reStartDeviceResponse")
    RespCodeEntity reStartDeviceResponse(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.DEVICE_RESTART, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 音量调节的回复
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/volumeAdjustResponse")
    RespCodeEntity volumeAdjustResponse(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.VOLUME_ADJUSTMENT, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 切换设备id的回复
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/changeIdResponse")
    RespCodeEntity changeIdResponse(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.CHANGE_DEVICE_ID, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 单独白名单回复
     *
     * @param mqSingleWhiteCallResult
     * @return
     */
    @PostMapping("/whiteCallResponse")
    RespCodeEntity whiteCallResponse(@RequestBody MqSingleWhiteCallResult mqSingleWhiteCallResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SINGLE_WHITELIST_NUMBER, mqSingleWhiteCallResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 一次设置全部白名单
     *
     * @param mqAllWhiteCallResult
     * @return
     */
    @PostMapping("/allWhiteCallResponse")
    RespCodeEntity allWhiteCallResponse(@RequestBody MqAllWhiteCallResult mqAllWhiteCallResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.ALL_WHITELIST_NUMBER, mqAllWhiteCallResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 一次性设置全部sos号码
     *
     * @param mqAllSosResult
     * @return
     */
    @PostMapping("/allSosResponse")
    RespCodeEntity allSosResponse(@RequestBody MqAllSosResult mqAllSosResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.ALL_SOS_PHONE, mqAllSosResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }


    /**
     * 白名单开关回复
     *
     * @param mqGeneralSwitchResult
     * @return
     */
    @PostMapping("/whiteCallSwitch")
    RespCodeEntity whiteCallSwitch(@RequestBody MqGeneralSwitchResult mqGeneralSwitchResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.WHITELIST_SWITCH, mqGeneralSwitchResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * SOS上报
     *
     * @param mqSOSUpMessage
     * @return
     */
    @PostMapping("/sosMessage")
    RespCodeEntity upSOSMessage(@RequestBody MqSOSUpMessage mqSOSUpMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SOS_WARNING, mqSOSUpMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 低电量上报
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/lowBatteryMessage")
    RespCodeEntity upLowBatteryMessage(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.LOW_BATTERY_WARNING, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * mqGeneralValueResult
     *
     * @param mqHeartBeatMessage
     * @return
     */
    @PostMapping("/heartBeatMessage")
    RespCodeEntity upHeartBeatMessage(@RequestBody MqHeartBeatMessage mqHeartBeatMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.HEARTBEAT, mqHeartBeatMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 步数上报数据
     *
     * @param mqStepAndBatteryMessage
     * @return
     */
    @PostMapping("/stepMessage")
    RespCodeEntity upStepMessage(@RequestBody MqStepAndBatteryMessage mqStepAndBatteryMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.ACTIVE_UPLOAD_STEP, mqStepAndBatteryMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 主动获取之后的步数上报数据
     *
     * @param mqStepAndBatteryMessage
     * @return
     */
    @PostMapping("/activeGetStepMessage")
    RespCodeEntity activeGetStepMessage(@RequestBody MqStepAndBatteryMessage mqStepAndBatteryMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.GET_DEVICE_STEP, mqStepAndBatteryMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 通话记录上报
     *
     * @param mqCallNoteMessage
     * @return
     */
    @PostMapping("/callNoteMessage")
    RespCodeEntity upCallNoteMessage(@RequestBody MqCallNoteMessage mqCallNoteMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.CALL_RECORDS, mqCallNoteMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 监听记录上报
     *
     * @param mqCallNoteMessage
     * @return
     */
    @PostMapping("/monitorNoteMessage")
    RespCodeEntity monitorNoteMessage(@RequestBody MqCallNoteMessage mqCallNoteMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.MONITOR_RECORDS, mqCallNoteMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 上报wifiMac
     *
     * @param mqWifiData
     * @return
     */
    @PostMapping("/wifiMac")
    RespCodeEntity uploadWifiMac(@RequestBody MqWifiData mqWifiData) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.WIFIMAC, mqWifiData);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 开机上报
     *
     * @param mqPowerOnMessage
     * @return
     */
    @PostMapping("/powerOn")
    RespCodeEntity upPowerOn(@RequestBody MqPowerOnMessage mqPowerOnMessage) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.DEVICE_POWER_ON, mqPowerOnMessage);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    // 修改m1卡回复
    @PostMapping("/resetM1CardResponse")
    RespCodeEntity resetM1Card(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.RESET_M1_CARD, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 清除Sim卡
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/CleanSimCard")
    RespCodeEntity cleanSimCard(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.REMOVE_BINDING, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 关机告警
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/shutDownWarning")
    RespCodeEntity shutDownWarning(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SHUT_DOWN_WARNING, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置静默关机的回复
     *
     * @param mqGeneralSwitchResult
     * @return
     */
    @PostMapping("/setShutDownSilent")
    RespCodeEntity setShutDownSilent(@RequestBody MqGeneralSwitchResult mqGeneralSwitchResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SHUT_DOWN_SILENT, mqGeneralSwitchResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置闹钟的回复
     *
     * @param mqAlarmResult
     * @return
     */
    @PostMapping("/setAlarmReply")
    RespCodeEntity setAlarmReply(@RequestBody MqAlarmResult mqAlarmResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.ALARM_CLOCK, mqAlarmResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }


    /**
     * 删除闹钟的回复
     *
     * @param mqAlarmResult
     * @return
     */
    @PostMapping("/delAlarmReply")
    RespCodeEntity delAlarmReply(@RequestBody MqAlarmResult mqAlarmResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.DELETE_CLOCK, mqAlarmResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 下发文本的回复
     *
     * @param mqTextData
     * @return
     */
    @PostMapping("/sendTextReply")
    RespCodeEntity sendTextReply(@RequestBody MqTextData mqTextData) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SEND_TEXT, mqTextData);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }


    /**
     * 发送绑定状态的回复
     *
     * @param mqGeneralValueResult
     * @return
     */
    @PostMapping("/sendBindingStatusReply")
    RespCodeEntity sendBindingStatusReply(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.DEVICE_BINDING_STATUS, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 考勤机的注册指令上报
     *
     * @param mqAttendanceData
     * @return
     */
    @PostMapping("/attendanceRegistry")
    RespCodeEntity attendanceRegistry(@RequestBody MqAttendanceData mqAttendanceData) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.IDENTITY, mqAttendanceData);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 考勤机的打卡信息上报
     *
     * @param attendanceSendDataList
     * @return
     */
    @PostMapping("/sendAttendanceData")
    RespCodeEntity sendAttendanceData(@RequestBody AttendanceSendDataList attendanceSendDataList) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.SEND_DATA, attendanceSendDataList);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    // 威科姆免打扰
    @PostMapping("/vcomNotDisturb")
    RespCodeEntity vcomNotDisturbReply(@RequestBody MqGeneralReply mqGeneralReply) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.VCOM_NOT_DISTURB, mqGeneralReply);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    // 威科姆通知消息
    @PostMapping("/vcomNoticeMessage")
    RespCodeEntity vcomNoticeMessage(@RequestBody MqGeneralReply mqGeneralReply) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.VCOM_NOTICE_MESSAGE, mqGeneralReply);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    // 威科姆短消息
    @PostMapping("/vcomShortMessage")
    RespCodeEntity vcomShortMessage(@RequestBody MqGeneralReply mqGeneralReply) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.VCOM_SHORT_MESSAGE, mqGeneralReply);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }


    //威科姆对接获取联通密匙
    @PostMapping("/getLtAuthKey")
    RespCodeEntity getLtAuthKey(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.GET_LT_AUTH_KEY, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    @PostMapping("/getPhone")
    public RespCodeEntity getPhone(@RequestBody MqGeneralValueResult mqGeneralValueResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.GET_PHONE, mqGeneralValueResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 用于设备上传app信息
     *
     * @param mqUpLoadApp
     * @return
     */
    @PostMapping("/upLoadApp")
    public RespCodeEntity upLoadApp(@RequestBody MqUpLoadApp mqUpLoadApp) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.UPLOAD_APP, mqUpLoadApp);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 用于上传app文件
     *
     * @param mqUplocadAppFile
     * @return
     */
    @PostMapping("/upLoadAppFile")
    public RespCodeEntity upLoadAppFile(@RequestBody MqUplocadAppFile mqUplocadAppFile) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.UPLOAD_APP_FILE, mqUplocadAppFile);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置app安装回复
     *
     * @param mqGeneralSwitchResult
     * @return
     */
    @PostMapping("/setAppInstallationReceiver")
    public RespCodeEntity setAppInstallationReceiver(@RequestBody MqGeneralSwitchResult mqGeneralSwitchResult) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.APP_INSTALLATION, mqGeneralSwitchResult);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置app禁用回复
     *
     * @param mqAppDisable
     * @return
     */
    @PostMapping("/setAppDisableReceiver")
    public RespCodeEntity setAppDisableReceiver(@RequestBody MqAppDisable mqAppDisable) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.APP_DISABLE, mqAppDisable);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }


    /**
     * 设置锁网回复
     *
     * @param lockNet
     * @return
     */
    @PostMapping("/setLockNetReceiver")
    public RespCodeEntity setLockNetReceiver(@RequestBody MqLockNet lockNet) {
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.LOCK_NET, lockNet);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置锁卡回复
     *
     * @param mqLockCard
     * @return
     */
    @PostMapping("/setLockCardReceiver")
    public RespCodeEntity setLockCardReceiver(@RequestBody MqLockCard mqLockCard){
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.LOCK_CARD, mqLockCard);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 设置锁机回复
     *
     * @param mqLockDevice
     * @return
     */
    @PostMapping("/setLockDeviceReceiver")
    public RespCodeEntity setLockDeviceReceiver(@RequestBody MqLockDevice mqLockDevice){
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.LOCK_DEVICE, mqLockDevice);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 同步设备锁卡状态回复
     *
     * @param mqLockCard
     * @return
     */
    @PostMapping("/getLockCardReceiver")
    public RespCodeEntity getLockCardReceiver(@RequestBody MqLockCard mqLockCard){
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.GET_LOCK_CARD, mqLockCard);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 同步锁机状态
     *
     * @param mqLockDevice
     * @return
     */
    @PostMapping("/getLockDeviceReceiver")
    public RespCodeEntity getLockDeviceReceiver(@RequestBody MqLockDevice mqLockDevice){
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.GET_LOCK_DEVICE, mqLockDevice);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 同步锁网状态
     *
     * @param lockNet
     * @return
     */
    @PostMapping("/getLockNetReceiver")
    public RespCodeEntity getLockNetReceiver(@RequestBody MqLockNet lockNet){
        RespCode respCode = RespCode.SUCCESS;
        byte[] messages = getMqMessage(Constants.GET_LOCK_NET, lockNet);
        try {
            sendMQMsg(producerConfig.getMangerBackStageTopic(), producerConfig.getMangerBackStageTag(), messages);
        } catch (RemotingException | MQClientException | InterruptedException e) {
            e.printStackTrace();
        }
        return new RespCodeEntity(respCode);
    }

    /**
     * 获取MQ发送消息
     *
     * @param type
     * @param object
     * @return
     */
    public byte[] getMqMessage(String type, Object object) {
        MqMessage mqMessage = new MqMessage();
        mqMessage.setType(type);
        mqMessage.setObject(object);
        byte[] msg = ByteObjectUtils.toByteArray(mqMessage);
        return msg;
    }


    /**
     * 发送MQMsg
     *
     * @param topic
     * @param tag
     * @param msg
     * @throws RemotingException
     * @throws MQClientException
     * @throws InterruptedException
     */
    private void sendMQMsg(String topic, String tag, byte[] msg) throws RemotingException, MQClientException, InterruptedException {
        Message message = new Message(topic, tag, msg);
        // 这里用到了这个mq的异步处理，类似ajax，可以得到发送到mq的情况，并做相应的处理
        // 不过要注意的是这个是异步的
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                logger.info("传输成功," + JSON.toJSONString(sendResult));
            }

            @Override
            public void onException(Throwable e) {
                logger.error("传输失败", e);
            }
        });
    }
}
